package com.oocl.util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.commons.dbcp.BasicDataSource;

public class DBUtil {
	private static String className = "oracle.jdbc.OracleDriver";
	private static String url = "jdbc:oracle:thin:@zha-ita114-w7:1521:wtip";// 这就是协议
	private static String username = "jasper";
	private static String psd = "123";
	
	private static BasicDataSource ds;
	
	static{
		ds = new BasicDataSource();
		ds.setUrl(url);
		ds.setDriverClassName(className);
		ds.setUsername(username);
		ds.setPassword(psd);
		ds.setMaxActive(20);
	}
	

	public static Connection createConnection() {
		Connection conn = null;
		try {
			conn = ds.getConnection();
		}catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}

	public static void close(Connection conn , PreparedStatement pst, ResultSet rs){
		try{
			if(pst!=null)
			pst.close();
			if(rs!=null)
			rs.close();
			if(conn !=null)
			conn.close();
		}catch(SQLException e){
			e.printStackTrace();
		}
	}
}
